package com.ssy.lingxi.platform.manage.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.manage.entity.seo.Seo;
import com.ssy.lingxi.platform.manage.model.request.common.CommonIdRequest;
import com.ssy.lingxi.platform.manage.model.request.common.CommonStatusRequest;
import com.ssy.lingxi.platform.manage.model.request.seo.SeoListRequest;
import com.ssy.lingxi.platform.manage.model.request.seo.SeoRequest;
import com.ssy.lingxi.platform.manage.service.ISeoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @menu 平台后台 - SEO优化 - SEO设置
 * @author fhj
 * @version 2.0.0
 * @date 2021/04/07
 */
@Api(tags = "平台后台 - SEO优化 - SEO设置")
@RestController
@RequestMapping("/manage/seo")
public class SeoController extends BaseController {

    @Resource
    private ISeoService seoService;
    @Resource
    private HttpServletRequest httpServletRequest;

    @ApiOperation(value = "列表")
    @GetMapping("/page")
    public Wrapper<PageData<Seo>> page(SeoListRequest request) {
        return seoService.page(request, getSysUser(httpServletRequest));
    }

    @ApiOperation(value = "详情")
    @GetMapping(value = "/get")
    public Wrapper<Seo> get(@Validated CommonIdRequest request) {
        return seoService.get(request, getSysUser(httpServletRequest));
    }

    @ApiOperation(value = "新增")
    @PostMapping(value = "/add")
    public Wrapper<Void> add(@RequestBody @Validated({SeoRequest.Add.class}) SeoRequest request) {
        return seoService.add(request, getSysUser(httpServletRequest));
    }

    @ApiOperation(value = "修改")
    @PostMapping(value = "/update")
    public Wrapper<Void> update(@RequestBody @Validated({SeoRequest.Update.class}) SeoRequest request) {
        return seoService.update(request, getSysUser(httpServletRequest));
    }

    @ApiOperation(value = "停用/启用")
    @PostMapping(value = "/updateStatus")
    public Wrapper<Void> updateStatus(@RequestBody @Validated ({CommonStatusRequest.Enable.class}) CommonStatusRequest request) {
        return seoService.updateStatus(request, getSysUser(httpServletRequest));
    }

    @ApiOperation(value = "删除")
    @PostMapping(value = "/delete")
    public Wrapper<Void> delete(@RequestBody @Validated CommonIdRequest request) {
        return seoService.delete(request, getSysUser(httpServletRequest));
    }

    @ApiOperation(value = "根据类型获取")
    @GetMapping(value = "/byType")
    public Wrapper<Seo> byType(Integer type) {
        return seoService.byType(type);
    }
}
